﻿using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Formatting;
using Newtonsoft.Json;
using ProtoBuf;
using Sustainalytics.ESGRatings.DataContract.ESG;
using Sustainalytics.Entities;


namespace Sustainalytics.ESGRatings.DataContract.Governance
{

    public class GovernanceRatingOptionDto
    {
        public Guid SetId { get; set; }
        public Guid MatrixId { get; set; }


        public GovernanceRatingOptionDto()
        {
            IncludeWeights = true;
            IncludeAggregatedWeights = true;
        }

        public bool IncludeWeights { get; set; }

        public bool IncludeAggregatedWeights { get; set; }
    }


    [ProtoContract]
    public class GovernanceRatingsDto
    {
        [ProtoMember(1)]
        public Guid SetId { get; set; }

        [ProtoMember(2)]
        public IndicatorsGroupsDto IssuesCodes { get; set; }

        [ProtoMember(3)]
        public IList<CompanyRatingDto> CompanyRating { get; set; }

       
        public GovernanceRatingsDto()
        {
            CompanyRating=new List<CompanyRatingDto>();
        }

        public override string ToString()
        {
            var result = new ObjectContent<string>(JsonConvert.SerializeObject(this),
                 new JsonMediaTypeFormatter());
            return result.ReadAsStringAsync().Result.Replace(@"\""", @"""");
        }
    }

     [ProtoContract]
    public class IssueScoreDto
    {
         [ProtoMember(1)]
        public float Score { get; set; }

         [ProtoMember(2)]
        public string Issue { get; set; }

         [ProtoMember(3)]
         public float Weight { get; set; }

         [ProtoMember(4)]
         public float WeightedScore { get; set; }
    }

    [ProtoContract]
    public class CompanyRatingDto
    {
        [ProtoMember(1)]
        public Guid CompanyId { get; set; }

        [ProtoMember(2)]
        public IList<IssueScoreDto> Scores { get; set; }

        [ProtoMember(3)]
        public Dictionary<PerformanceType,CompanyComparativeGroupBenchmarksDto> CompanyBenchmarks { get; set; }

        public CompanyRatingDto()
        {
            Scores = new List<IssueScoreDto>();
            CompanyBenchmarks=new Dictionary<PerformanceType, CompanyComparativeGroupBenchmarksDto>();
        }
    }


    [ProtoContract]
    public class CompanyComparativeGroupBenchmarksDto
    {
      
        [ProtoMember(1)]
        public int GroupIndex { get; set; }

        [ProtoMember(2)]
        public IList<IssueBenchmarksDto> Benchmarks { get; set; }

        public CompanyComparativeGroupBenchmarksDto()
        {
             Benchmarks=new List<IssueBenchmarksDto>();
        }
    }

    [ProtoContract]
    public class IssueBenchmarksDto
    {
        [ProtoMember(1)]
        public string Issue { get; set; }
       
        [ProtoMember(2)]
        public CompanyGroupValuesDto IssueBenchmark { get; set; }
    }

}